package com.rndemo.Environmental;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.os.Handler;
import android.os.Looper;
import android.view.WindowManager;
import android.widget.Toast;

import com.rndemo.BuildConfig;

/**
 * 这是一个app运行环境的一部分
 * 这里主要放一些app运行时会变的量
 */
public class AppData {
    static {
        System.loadLibrary("native-lib");
    }
    public static Application mAppCxt;
    public static Handler mHandler;
    public static Toast mToast;

    public static String versionName;
    public static int versionCode;
    public static int scrnWidth;
    public static int scrnHeight;
    public static float density;

    public static void init(Application ctx){
        soInit(ctx);
        mAppCxt = ctx;
        mHandler = new Handler(Looper.getMainLooper());
        mToast = Toast.makeText(mAppCxt, "", Toast.LENGTH_LONG);
        try {
            PackageInfo packageInfo = mAppCxt.getPackageManager().getPackageInfo(mAppCxt.getPackageName(), 0);
            versionName = packageInfo.versionName;
            versionCode = packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            versionCode= BuildConfig.VERSION_CODE;
            versionName = BuildConfig.VERSION_NAME;
        }
        WindowManager wm = (WindowManager) mAppCxt.getSystemService(Context.WINDOW_SERVICE);
        Point outSize = new Point();
        wm.getDefaultDisplay().getSize(outSize);
        scrnWidth = outSize.x;
        scrnHeight = outSize.y;
        density = mAppCxt.getResources().getDisplayMetrics().density;
    }

    public static native void soInit(Context context);

}
